package top.haichi.webpaper.Interceptors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import top.haichi.webpaper.entity.Result;
import top.haichi.webpaper.utils.InterceptorUtils;
import top.haichi.webpaper.utils.JwtUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class TeacherInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String status = JwtUtils.getTokenParam(request, "status");
        if ((status==null||(!status.equals("teacher")))
//               || !(JwtUtils.verifyJwtWithParam(request,"id","id"))
        ) {
            InterceptorUtils.result(Result.tokenError(), response);
            return false;
        }

        return true;
    }
}
